home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97b.txt / 000087_icon-group-sender _Mon Oct 20 12:33:06 1997.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
  3.     by cheltenham.cs.arizona.edu (8.8.7/8.8.7) with SMTP id MAA28725
  4.     for <icon-group-addresses@cheltenham.CS.Arizona.EDU>; Mon, 20 Oct 1997 12:33:06 -0700 (MST)
  5. Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
  6.     id AA19468; Mon, 20 Oct 1997 12:33:05 -0700
  7. From: gep2@computek.net
  8. Date: Mon, 20 Oct 1997 12:11:29 -0500
  9. Message-Id: <199710201711.MAA10989@axp.cmpu.net>
  10. Mime-Version: 1.0
  11. Content-Type: text/plain
  12. Content-Transfer-Encoding: 7bit
  13. Subject: counting letters
  14. To: icon-group@cs.arizona.edu
  15. X-Mailer: SPRY Mail Version: 04.00.06.17
  16. Errors-To: icon-group-errors@cs.arizona.edu
  17. Status: RO
  18.  
  19. >What would be the best way to design an Icon program that takes a text
  20. file as input, counts up the instances of every letter in the alphabet
  21. (ignoring other characters and distinguishing between uppercase and
  22. lowercase letters), and spits out the results of the count as output?
  23.  
  24. Define "best"... smallest, simplest, fastest, most elegant?
  25.  
  26. >For example, the following input
  27. abcdefghjijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()
  28. would produce the following output
  29.  
  30. >a  1
  31. b  2
  32. [etc.]
  33. A  1
  34. b  2
  35. [etc.]
  36. [nothing for the non-alphabetic characters]
  37.  
  38. In SNOBOL4+/SPITBOL, one program would be:
  39.  
  40. -PLUSOPS 1
  41.           T = TABLE()
  42.           CHRSET = &LCASE &UCASE
  43. GETREC    LINE = INPUT                  :F(EOF)
  44. COUNT     LINE BREAK(CHRSET) ANY(CHRSET) . LET = ?(T[LET] = T[LET] + 1) 
  45. +                                                        :S(COUNT)F(GETREC)
  46. EOF       A = SORT(TABLE,1)             :F(DONE)
  47. LIST      OUTPUT = A[(N = N + 1),1] "  " A[N,2]          :S(LIST)
  48. END
  49.  
  50. Gordon Peterson
  51. http://www.computek.net/public/gep2/
  52. Support the Anti-SPAM Amendment!  Join at http://www.cauce.org/
  53.  
  54.